/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/

#include <string.h>
#include "flgrCoreErrors.h"
#include "flgrCoreTypes.h"
#include "flgrCoreDispatch.h"


  /*!
   * \addtogroup group_fulguro_core
   * @{
   */

//////////////////////////////////////////////////////////////////
/*! Test if a type defined in a string is Valid
 *  @param type
 *  @returns FLGR_RET_OK, FLGR_RET_TYPE_UNKNOWN
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr_is_vector_type_valid(FLGR_Type type) {
  FLGR_DECLARE_FUNCTION;

  if(type==FLGR_UINT8) {
    return FLGR_RET_OK;
  }else if(type==FLGR_UINT16) {
    return FLGR_RET_OK;
  }else if(type==FLGR_UINT32) {
    return FLGR_RET_OK;
  }else if(type==FLGR_UINT64) {
    return FLGR_RET_OK;
  }else if(type==FLGR_INT8) {
    return FLGR_RET_OK;
  }else if(type==FLGR_INT16) {
    return FLGR_RET_OK;
  }else if(type==FLGR_INT32) {
    return FLGR_RET_OK;
  }else if(type==FLGR_INT64) {
    return FLGR_RET_OK;
  }else if(type==FLGR_FLOAT32) {
    return FLGR_RET_OK;
  }else if(type==FLGR_FLOAT64) {
    return FLGR_RET_OK;
  }else if(type==FLGR_BIT) {
    return FLGR_RET_OK;
  }else return FLGR_RET_TYPE_UNKNOWN;
}

//////////////////////////////////////////////////////////////////
/*! Test if a type defined in a string is Valid
 *  @param type
 *  @returns FLGR_RET_OK, FLGR_RET_TYPE_UNKNOWN
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr_is_data_type_valid(FLGR_Type type) {
  FLGR_DECLARE_FUNCTION;

  if(type==FLGR_UINT8) {
    return FLGR_RET_OK;
  }else if(type==FLGR_UINT16) {
    return FLGR_RET_OK;
  }else if(type==FLGR_UINT32) {
    return FLGR_RET_OK;
  }else if(type==FLGR_INT8) {
    return FLGR_RET_OK;
  }else if(type==FLGR_INT16) {
    return FLGR_RET_OK;
  }else if(type==FLGR_INT32) {
    return FLGR_RET_OK;
  }else if(type==FLGR_FLOAT32) {
    return FLGR_RET_OK;
  }else if(type==FLGR_FLOAT64) {
    return FLGR_RET_OK;
  }else if(type==FLGR_BIT) {
    return FLGR_RET_OK;
  }else return FLGR_RET_TYPE_UNKNOWN;
}

//////////////////////////////////////////////////////////////////
/*! Get Number of Bit Per Pixel for a given type
 *  @param type
 *  @returns bps or FLGR_RET_TYPE_UNKNOWN
 */
//////////////////////////////////////////////////////////////////
int flgr_get_bps_from_type(FLGR_Type type) {
  FLGR_DECLARE_FUNCTION;

  switch(type) {
  case FLGR_BIT     : return 1;
  case FLGR_UINT8   : return (sizeof(fgUINT8))<<3;
  case FLGR_UINT16  : return (sizeof(fgUINT16))<<3;
  case FLGR_UINT32  : return (sizeof(fgUINT32))<<3;
  case FLGR_UINT64  : return (sizeof(fgUINT64))<<3;
  case FLGR_INT8    : return (sizeof(fgINT8))<<3;
  case FLGR_INT16   : return (sizeof(fgINT16))<<3;
  case FLGR_INT32   : return (sizeof(fgINT32))<<3;
  case FLGR_INT64   : return (sizeof(fgINT64))<<3;
  case FLGR_FLOAT32 : return (sizeof(fgFLOAT32))<<3;
  case FLGR_FLOAT64 : return (sizeof(fgFLOAT64))<<3;
  default:
    return FLGR_RET_TYPE_UNKNOWN;
  }

}

//////////////////////////////////////////////////////////////////
/*! Get size of type in byte
 *  @param type
 *  @returns Byte Per Pixel or FLGR_RET_TYPE_UNKNOWN
 */
//////////////////////////////////////////////////////////////////
int flgr_get_sizeof(FLGR_Type type) {
  FLGR_DECLARE_FUNCTION;

  switch(type) {
  case FLGR_BIT     : return sizeof(fgBIT);
  case FLGR_UINT8   : return sizeof(fgUINT8);
  case FLGR_UINT16  : return sizeof(fgUINT16);
  case FLGR_UINT32  : return sizeof(fgUINT32);
  case FLGR_UINT64  : return sizeof(fgUINT64);
  case FLGR_INT8    : return sizeof(fgINT8);
  case FLGR_INT16   : return sizeof(fgINT16);
  case FLGR_INT32   : return sizeof(fgINT32);
  case FLGR_INT64   : return sizeof(fgINT64);
  case FLGR_FLOAT32 : return sizeof(fgFLOAT32);
  case FLGR_FLOAT64 : return sizeof(fgFLOAT64);
  default:
    return FLGR_RET_TYPE_UNKNOWN;
  }
}

//////////////////////////////////////////////////////////////////
/*! Get the type flag string
 *  @param type
 *  @returns string
 */
//////////////////////////////////////////////////////////////////
char *flgr_get_type_string(FLGR_Type type) {
  FLGR_DECLARE_FUNCTION;

  switch(type) {
  case FLGR_BIT     : return "fgBIT";
  case FLGR_UINT8   : return "fgUINT8";
  case FLGR_UINT16  : return "fgUINT16";
  case FLGR_UINT32  : return "fgINT32";
  case FLGR_UINT64  : return "fgINT64";
  case FLGR_INT8    : return "fgINT8";
  case FLGR_INT16   : return "fgINT16";
  case FLGR_INT32   : return "fgINT32";
  case FLGR_INT64   : return "fgINT64";
  case FLGR_FLOAT32 : return "fgFLOAT32";
  case FLGR_FLOAT64 : return "fgFLOAT64";
  default:
    return "UNKNOWN_TYPE";
  }
}

//////////////////////////////////////////////////////////////////
/*! Get the type flag string
 *  @param shape
 *  @returns string
 */
//////////////////////////////////////////////////////////////////
char *flgr_get_shape_string(FLGR_Shape shape) {
  FLGR_DECLARE_FUNCTION;

  switch(shape) {
  case FLGR_LINE       : return "LINE";
  case FLGR_RECT       : return "RECT";
  case FLGR_HEX        : return "HEX";
  case FLGR_DISC       : return "DISC";
  case FLGR_CROSS      : return "CROSS";
  case FLGR_CROSSX     : return "CROSSX";
  case FLGR_SLASH      : return "SLASH";
  case FLGR_BSLASH     : return "BSLASH";
  case FLGR_DIAMOND    : return "DIAMOND";
  case FLGR_OCTAGON    : return "OCTAGON";
  case FLGR_USER_SHAPE : return "USER_SHAPE";
  case FLGR_NO_SHAPE   : return "NO_SHAPE";
  default:
    return "UNKNOWN_SHAPE";
  }
}

//////////////////////////////////////////////////////////////////
/*! Get the type flag string
 *  @param type
 *  @returns string
 */
//////////////////////////////////////////////////////////////////
FLGR_Type flgr_get_type_from_string(char *type) {
  FLGR_DECLARE_FUNCTION;

  if(strcmp(type,"fgBIT")==0) return FLGR_BIT;
  if(strcmp(type,"fgUINT8")==0) return FLGR_UINT8;
  if(strcmp(type,"fgUINT16")==0) return FLGR_UINT16;
  if(strcmp(type,"fgUINT32")==0) return FLGR_UINT32;
  if(strcmp(type,"fgUINT64")==0) return FLGR_UINT64;
  if(strcmp(type,"fgINT8")==0) return FLGR_INT8;
  if(strcmp(type,"fgINT16")==0) return FLGR_INT16;
  if(strcmp(type,"fgINT32")==0) return FLGR_INT32;
  if(strcmp(type,"fgINT64")==0) return FLGR_INT64;
  if(strcmp(type,"fgFLOAT32")==0) return FLGR_FLOAT32;
  if(strcmp(type,"fgFLOAT64")==0) return FLGR_FLOAT64;

  POST_ERROR("Unknown type %s\n",type);
  return FLGR_UINT8;
}




//! @}
